6 #define D(x) cout << #x " = " << (x) << endl
11 int dist(int x1
, int y1
, int x2
, int y2
){
14 return dx
* dx
+ dy
* dy
;
18 typedef pair
<int, int> point
;
21 vector
<point
> people
, chairs
;
24 vector
<int> peopleFor
[MAXN
];
26 int dist(int guy
, int chair
){
27 return dist(people
[guy
].first
, people
[guy
].second
, chairs
[chair
].first
, chairs
[chair
].second
);
32 for (int i
= 0; i
< rows
; ++i
){
33 for (int j
= 0; j
< cols
; ++j
){
35 if (mat
[i
][j
] == 'X') people
.push_back(point(i
, j
));
36 if (mat
[i
][j
] == 'L') chairs
.push_back(point(i
, j
));
40 for (int i
= 0; i
< people
.size(); ++i
){
44 vector
<pair
<int, pair
<int, int> > > options
;
45 for (int i
= 0; i
< people
.size(); ++i
){
46 for (int j
= 0; j
< chairs
.size(); ++j
){
47 options
.push_back(make_pair(dist(i
, j
), make_pair(i
, j
)));
51 sort(options
.begin(), options
.end());
52 for (int k
= 0; k
< options
.size(); ++k
){
53 int d
= options
[k
].first
;
54 int guy
= options
[k
].second
.first
;
55 int chair
= options
[k
].second
.second
;
56 if (chairFor
[guy
] != -1) continue; //already seated
57 if (peopleFor
[chair
].size() == 0 ||
58 dist(peopleFor
[chair
][0], chair
) == d
){
59 chairFor
[guy
] = chair
;
60 peopleFor
[chair
].push_back(guy
);
64 // for (int i = 0; i < people.size(); ++i){
69 for (int c
= 0; c
< chairs
.size(); ++c
){
70 ans
+= (peopleFor
[c
].size() > 1);